Skip to content

refactor(fspy): simplify shm_io to a plain frame arena - #578

Draft
wan9chi wants to merge 1 commit into
fspy-close-gatefrom
fspy-plain-frame-arena
Draft

refactor(fspy): simplify shm_io to a plain frame arena#578
wan9chi wants to merge 1 commit into
fspy-close-gatefrom
fspy-plain-frame-arena

Conversation

@wan9chi

@wan9chi wan9chi commented Jul 28, 2026

Copy link
Copy Markdown
Member

Motivation

The gated API reads shared memory only when the gate is closed and nothing was in flight, which proves every claimed frame was written in full; the gate guard is released after the frame drops. The three-state frame header (0 / +size / -size), the atomic header stores and the release fences in shm_io existed so a reader could tolerate crashed or in-flight writers. Those states are unreachable through the gated API.

This PR deletes them. The arena keeps one atomic, its end-offset word. A frame becomes | size: u32 | content | padding |, written once at claim time with a plain store: the claim made the range exclusive, and the gate release publishes the content. Crash exclusion lives in the gate, where a leaked count means the run is not cached. The arena stops being a public surface and becomes an internal of the gated module. Mapping::as_slice goes away with its last caller, which leaves fspy_shm without unsafe API.

write_encoded enters the gate before it sizes the value, so a post-close call reports Claim(Closed) for any value, including one that encodes to zero bytes.

No public API change: GatedShmWriter, GatedShmReceiver, GatedShmReader, FrameMut, ClaimError and StillWriting keep their signatures. The channel layer, the fspy crate and both preload clients are untouched.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown

fspy benchmark

linux

dynamic/launch             change  +0.64%  [ -6.76% ..  +8.56%]  overhead  +288.50%
dynamic/access             change  +1.18%  [ -6.61% .. +12.48%]  overhead    +9.79%
dynamic/access-relative    change  +1.84%  [ -7.34% .. +10.01%]  overhead   +45.76%
static/launch              change  +0.35%  [ -6.44% ..  +7.33%]  overhead  +646.36%
static/access              change  -0.70%  [ -7.58% ..  +5.74%]  overhead  +819.38%
static/access-relative     change  +0.71%  [ -9.72% ..  +9.33%]  overhead +1130.59%

macos

dynamic/launch             change  +0.41%  [ -3.70% ..  +4.00%]  overhead  +224.63%
dynamic/access             change  -0.34%  [ -2.66% ..  +1.38%]  overhead    +6.14%
dynamic/access-relative    change  -0.21%  [ -2.22% ..  +3.22%]  overhead  +264.51%

windows

dynamic/launch             change  +0.32%  [ -3.60% ..  +3.66%]  overhead   +26.60%
dynamic/access             change  +0.00%  [ -1.28% ..  +1.12%]  overhead    +1.69%
dynamic/access-relative    change  -0.18%  [ -0.73% ..  +0.55%]  overhead    +1.46%

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b03e50b979

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/fspy_shared/src/ipc/channel/gated.rs
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from 9485184 to a815712 Compare July 28, 2026 11:18
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch 2 times, most recently from 98eff10 to 4deba7a Compare July 29, 2026 01:22
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from 4deba7a to d5fee65 Compare July 29, 2026 02:14
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch 2 times, most recently from 43075cc to b8e397b Compare July 30, 2026 02:14
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from b8e397b to b6e4c6e Compare July 30, 2026 03:24
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from b6e4c6e to fb46de4 Compare July 30, 2026 03:43
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch 2 times, most recently from d341ace to b5602be Compare July 30, 2026 03:51
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from b5602be to 2ecce74 Compare July 30, 2026 04:11
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from 2ecce74 to 7c7e5c2 Compare July 30, 2026 04:36
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch 2 times, most recently from a37218d to d27bdce Compare July 30, 2026 08:18
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch 2 times, most recently from d4ac10b to 000892d Compare July 30, 2026 09:03
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from 000892d to befccd8 Compare July 30, 2026 09:07
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from befccd8 to 4a6f37a Compare July 31, 2026 06:31
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch 2 times, most recently from 1bb2940 to e052585 Compare August 4, 2026 10:17
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from e052585 to cc1597c Compare August 4, 2026 10:21
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from cc1597c to f22bcdd Compare August 10, 2026 06:59
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch 2 times, most recently from 94c32e9 to c314777 Compare August 10, 2026 07:07
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from c314777 to 000a881 Compare August 10, 2026 07:26
The gated API reads shared memory only when the gate is closed and nothing
was in flight, which proves every claimed frame was fully written and
published. The three-state frame header (`0` / `+size` / `-size`), the
atomic header stores and the release fences existed so a reader could
tolerate crashed or in-flight writers — states that are unreachable through
the gate.

Delete them. A frame is now `| size: u32 | content | padding |`, written
once at claim time with a plain store, and the arena keeps exactly one
atomic: its end offset. Crash exclusion lives entirely in the gate, where a
leaked count fails closed — the run is not cached — instead of being parsed
around. The arena also stops being a surface of its own and becomes an
internal of the gated module.

No public API change: `GatedShmWriter`, `GatedShmReceiver`,
`GatedShmReader`, `FrameMut`, `ClaimError` and `StillWriting` keep their
signatures, so the channel layer, the fspy crate and both preload clients
are untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from 000a881 to 2bf69b4 Compare August 10, 2026 07:32
@wan9chi
wan9chi marked this pull request as draft August 10, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant